<template>
	<view class="container">
		<!-- 顶部导航栏 -->
		<bg-navBar :title="'添加零担'"></bg-navBar>

		<!-- 零担说明 -->
		<view class="instruction-section">
			<view class="section-title">零担说明</view>
			<view class="instruction-content">
				<text class="instruction-text">您购买零担商品后需到集配现场自采登记窗口打印标签和</text>
				<text class="instruction-text">自采单;</text>
				<text class="instruction-text">自采单和标签作为装车依据;</text>
			</view>
		</view>

		<!-- 零担信息 -->
		<view class="info-section">
			<view class="section-header">
				<view class="section-title">零担信息</view>
				<button class="add-product-btn" @click="addProduct">添加商品</button>
			</view>

			<!-- 商品信息表单 -->
			<view class="form-container">
				<!-- 动态商品列表 -->
				<view v-for="(product, index) in productList" :key="product.id" class="product-item">
					<view class="product-header">
						<text class="product-title">商品{{ index + 1 }}</text>
						<view class="remove-btn" @click="removeProduct(product.id)" v-if="productList.length > 1">
							<u-icon name="minus" size="16" color="#fff"></u-icon>
						</view>
					</view>
					
					<view class="product-form">
						<view class="form-item">
							<view class="form-label">商品名称</view>
							<input type="text" placeholder="输入商品名称" class="form-input" v-model="product.productName" />
						</view>

						<view class="form-item">
							<view class="form-label">件数</view>
							<view class="form-input-container">
								<input type="number" placeholder="输入件数" class="form-input" v-model="product.quantity" />
								<text class="unit-text">件</text>
							</view>
						</view>

						<view class="form-item">
							<view class="form-label">每件斤数</view>
							<view class="form-input-container">
								<input type="number" placeholder="输入斤数" class="form-input" v-model="product.weightPerPiece" />
								<text class="unit-text">斤</text>
							</view>
						</view>

						<view class="form-item">
							<view class="form-label">总斤数</view>
							<view class="form-input-container">
								<input type="number" placeholder="输入斤数" class="form-input" v-model="product.totalWeight" />
								<text class="unit-text">斤</text>
							</view>
						</view>
					</view>
				</view>

				<!-- 收货信息 -->
				<view class="consignee-section">
					<view class="section-title">收货信息</view>
					
					<view class="form-item">
						<view class="form-label">城市仓</view>
						<view class="form-select" @click="selectCityWarehouse">
							<text class="select-text">{{ formData.cityWarehouse || '选择城市仓' }}</text>
							<u-icon name="arrow-right" size="16" color="#999"></u-icon>
						</view>
					</view>

					<view class="form-item">
						<view class="form-label">自提点</view>
						<view class="form-select" @click="selectPickupPoint">
							<text class="select-text">{{ formData.pickupPoint || '选择自提点' }}</text>
							<u-icon name="arrow-right" size="16" color="#999"></u-icon>
						</view>
					</view>

					<view class="form-item">
						<view class="form-label">收货人姓名</view>
						<input type="text" placeholder="输入收货人姓名" class="form-input" v-model="formData.consigneeName" />
					</view>
					
					<view class="form-item">
						<view class="form-label">收货人电话</view>
						<input type="text" placeholder="输入收货人电话" class="form-input" v-model="formData.consigneePhone" />
					</view>
				</view>
			</view>
		</view>

		<!-- 底部提交按钮 -->
		<view class="bottom-btn-container">
			<button class="register-btn" @click="submitForm">确认提交</button>
		</view>
	</view>
</template>

<script>
export default {
		data() {
			return {
				formData: {
					cityWarehouse: '',
					pickupPoint: '',
					consigneeName: '',
					consigneePhone: ''
				},
				productList: [
					{
						id: 1,
						productName: '',
						quantity: '',
						weightPerPiece: '',
						totalWeight: ''
					}
				],
				nextProductId: 2
			};
		},
		methods: {
			addProduct() {
				// 添加新商品
				this.productList.push({
					id: this.nextProductId,
					productName: '',
					quantity: '',
					weightPerPiece: '',
					totalWeight: ''
				});
				this.nextProductId++;
			},
			removeProduct(productId) {
				// 删除商品
				const index = this.productList.findIndex(item => item.id === productId);
				if (index > -1) {
					this.productList.splice(index, 1);
				}
			},
			selectCityWarehouse() {
				// 选择城市仓逻辑
				console.log('选择城市仓');
			},
			selectPickupPoint() {
				// 选择自提点逻辑
				console.log('选择自提点');
			},
			submitForm() {
				// 提交表单逻辑
				const submitData = {
					products: this.productList,
					consignee: this.formData
				};
				console.log('提交表单', submitData);
			}
		}
};
</script>

<style lang="scss">
.container {
	min-height: 100vh;
	background-color: #f5f5f5;
	padding-bottom: 140rpx;
}

.instruction-section {
	background-color: #fff;
	padding: 30rpx;
	margin-bottom: 20rpx;
}

.section-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #007aff;
	margin-bottom: 20rpx;
}

.instruction-content {
	.instruction-text {
		display: block;
		font-size: 28rpx;
		color: #333;
		line-height: 1.6;
		margin-bottom: 8rpx;
	}
}

.info-section {
	background-color: #fff;
	padding: 30rpx;
}

.section-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 30rpx;
	.section-title{
		margin-bottom: 0;
	}
}

.add-product-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #007aff;
	color: #fff;
	font-size: 28rpx;
	padding: 12rpx 24rpx;
	border-radius: 6rpx;
	border: none;
	margin: 0;
	
	height: 60rpx;
	
}

.form-container {
	.product-item {
		margin-bottom: 30rpx;
		background-color: #f8f9fa;
		border-radius: 12rpx;
		padding: 20rpx;
		border: 1rpx solid #e9ecef;
	}

	.product-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
		padding-bottom: 15rpx;
		border-bottom: 1rpx solid #e9ecef;
	}

	.product-title {
		font-size: 30rpx;
		font-weight: bold;
		color: #333;
	}

	.remove-btn {
		width: 40rpx;
		height: 40rpx;
		background-color: #ff4757;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.product-form {
		.form-item {
			display: flex;
			align-items: center;
			padding: 20rpx 0;
			border-bottom: 1rpx solid #e9ecef;

			&:last-child {
				border-bottom: none;
			}
		}

		.form-label {
			width: 200rpx;
			font-size: 28rpx;
			color: #333;
			flex-shrink: 0;
		}

		.form-input {
			flex: 1;
			font-size: 28rpx;
			color: #333;
			background: transparent;
			border: none;
			outline: none;
		}

		.form-input-container {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.unit-text {
			font-size: 28rpx;
			color: #999;
			margin-left: 20rpx;
		}
	}

	.consignee-section {
		margin-top: 40rpx;
		padding-top: 30rpx;
		border-top: 2rpx solid #e9ecef;

		.section-title {
			font-size: 32rpx;
			font-weight: bold;
			color: #007aff;
			margin-bottom: 30rpx;
		}

		.form-item {
			display: flex;
			align-items: center;
			padding: 24rpx 0;
			border-bottom: 1rpx solid #f0f0f0;

			&:last-child {
				border-bottom: none;
			}
		}

		.form-label {
			width: 200rpx;
			font-size: 28rpx;
			color: #333;
			flex-shrink: 0;
		}

		.form-input {
			flex: 1;
			font-size: 28rpx;
			color: #333;
			background: transparent;
			border: none;
			outline: none;
		}

		.form-select {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0;
		}

		.select-text {
			font-size: 28rpx;
			color: #333;
		}
	}
}
.bottom-btn-container {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
	padding: 0 30rpx;
	height: 140rpx;
	display: flex;
	align-items: center;
	background-color: #fff;
	.register-btn {
		width: 100%;
		height: 88rpx;
		background-color: #007aff;
		color: #fff;
		font-size: 32rpx;
		border-radius: 44rpx;
		border: none;
		display: flex;
		align-items: center;
		justify-content: center;
	}
}
</style>
